﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NET4.DataNET4;
using NET4.DataNET4.Repository;
using System.IO;
using System.Reflection;

namespace NET4.Programma
{
  public partial class OverviewOffer : Form
  {
    #region Properties
    private OfferteAanvraag offerRequest;
    public OfferteAanvraag OfferRequest
    {
      get { return this.offerRequest; }
      set { this.offerRequest = value; }
    }

    private IEnumerable<Offerte> offers;
    protected IEnumerable<Offerte> Offers
    {
      get { return this.offers; }
      set { this.offers = value; }
    }
    #endregion

    public OverviewOffer()
    {
      InitializeComponent();
    }

    #region Protected methods
    protected void Init()
    {
      this.Init(OfferteSoort.Ingevuld);
    }

    protected void Init(OfferteSoort offerKind)
    {
      this.cmbKind.Text = offerKind.ToString();

      this.txtQuantity.Text = this.OfferRequest.Aantal.ToString();
      this.txtDescription.Text = this.OfferRequest.Omschrijving;

      if (this.OfferRequest.Afbeelding != null)
      {
        MemoryStream ms = new MemoryStream(this.OfferRequest.Afbeelding.ToArray());
        this.pbImage.Image = Image.FromStream(ms);
      }

      this.Offers = OfferteRepository.Instance.ListByOfferRequestAndKind(this.OfferRequest, offerKind);

      this.dgvOffers.AutoGenerateColumns = false;
      this.dgvOffers.DataSource = this.Offers;
    }
    #endregion

    #region EventHandlers
    private void OverviewOffer_Load(object sender, EventArgs e)
    {
      this.Init();
    }

    private void cmbKind_SelectedIndexChanged(object sender, EventArgs e)
    {
      this.Init((OfferteSoort)Enum.Parse(typeof(OfferteSoort), this.cmbKind.Text));
    }
    #endregion
  }
}
